package org.example.fancystudy.basic;

import com.alibaba.druid.filter.config.ConfigTools;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
//import com.alibaba.druid.filter.config.ConfigTools;
//import com.ipms.framework.web.domain.server.Sys;
//import com.ipms.web.devops.AESUtils;
//import org.gitlab4j.api.*;
//import org.gitlab4j.api.models.Branch;
//import org.gitlab4j.api.models.Group;
//import org.gitlab4j.api.models.Project;
//import sun.security.util.Password;

import java.util.List;


/**
 * @author chaigq
 * @version 1.0
 * @date 2023/12/5 10:45
 */
public class JvmTest1 {
    public static void main(String[] args) throws Exception {
        try {
            String[] strings = ConfigTools.genKeyPair(512);
            //公钥
            String publickey = strings[1];
            System.out.print(publickey+"\n");
            System.out.print("---------------"+"\n");
            //密码  第二个参数为数据库明文密码，返回为加密后的密码
            String password = ConfigTools.encrypt(strings[0], "perioddb02");
            System.out.print(password);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }



//        int textPeriod = 2;
//        int[] periods = {2,3,4};
//        String erPeriod1 = "";
//        for(int i=0; textPeriod>i; i++){
//            if(i==0){
//                erPeriod1=erPeriod1+periods[i];
//            }else{
//                erPeriod1=erPeriod1+','+periods[i];
//            }
//        }
//        System.out.println("erPeriod1:" + erPeriod1);
        //除法运算
//        BigDecimal a = new BigDecimal(10);
//        BigDecimal b = new BigDecimal(3);
//        BigDecimal c = a.divide(new BigDecimal(360), 12, RoundingMode.HALF_UP);
//        System.out.println(c);

        /*String systemDate = DateTimeFormatter.ofPattern("YYYY-MM-dd").format(LocalDateTime.now());
        System.out.println(systemDate);
        System.out.println("当前日期时间为：" + LocalDateTime.now());
        String applyAmt=new BigDecimal("100000").divide(new BigDecimal("100")).toString();
        System.out.println(applyAmt);
        if (new BigDecimal(applyAmt).compareTo(new BigDecimal("1000"))<0 || new BigDecimal(applyAmt).compareTo(new BigDecimal("30000"))>0){
            System.out.println("applyAmt");
        }*/

//        List<Map<String, String>> businessDatas = new ArrayList<Map<String, String>>();
//        Map<String, String> businessDataList = new HashMap<String, String>();
//        businessDataList.put("docType", "sysUserName");
//        businessDataList.put("applyDate", "sysPassWord");
//        businessDataList.put("applyNumber", "sysCode");
//        businessDatas.add(businessDataList);
//        System.out.println("----------" + businessDatas.toString());
//
//        Map<String, String> publicInfo = new HashMap<String, String>();
//        publicInfo.put("currentUserName", "admin");
//        publicInfo.put("userPwd", "111111");
//        publicInfo.put("userName", "sjgr_Admin");
//        publicInfo.put("calledCategoryCode", "credit");
//        publicInfo.put("systemCode", "SJGR");
//        publicInfo.put("currentUserNumber", "admin");
//        System.out.println("----------" + publicInfo.toString());
//
//        List<Map<String, String>> fileInfos = new ArrayList<Map<String, String>>();
//        Map<String, String> fileInfosList = new HashMap<String, String>();
//        fileInfosList.put("docType", "00-002");
//        fileInfosList.put("addWaterFlag", "0");
//        fileInfos.add(fileInfosList);
//        System.out.println("----------" + fileInfos.toString());

//        Cell cell1 = null; // 获取第一个单元格
//        String loanNo = "";
//        if (cell1 != null && cell1.getCellType() == CellType.STRING ) { // 判断单元格类型是否为字符串类型
//            //String cellValue = cell1.getStringCellValue(); // 获取字符串类型的单元格值
//            System.out.println("----------");
//        }
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//
//        // 获取当前日期
//        LocalDate currentDate = LocalDate.now();
//        // 指定日期区间
//        LocalDate startDate = LocalDate.parse("2000-12-13", formatter);
//        LocalDate endDate = LocalDate.parse("2099-12-11", formatter);
//
//        if (currentDate.isEqual(startDate) || currentDate.isEqual(endDate) ||
//                (currentDate.isAfter(startDate) && currentDate.isBefore(endDate))) {
//            System.out.println(currentDate.toString());
//            System.out.println("当前日期在指定的区间内");
//        } else {
//            System.out.println("当前日期不在指定的区间内");
//        }
//
//
//        System.out.println("---------" + getCurrDate("2000-12-13"));
//
//        String idTermBgn = "";
//        String idTermEnd = "";
//
//        String date1 = "2023-12-31";
//        String date2 = "20231231";
//
//        if (isValidDateFormat(date1)) {
//            System.out.println(date1 + " 是 YYYY-MM-DD 格式的日期");
//        } else {
//            System.out.println(date1 + " 不是 YYYY-MM-DD 格式的日期");
//        }
//
//        if (isValidDateFormat(date2)) {
//            System.out.println(date2 + " 是 YYYY-MM-DD 格式的日期");
//        } else {
//            System.out.println(date2 + " 不是 YYYY-MM-DD 格式的日期");
//        }
//
//
//        System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
// 105
        //System.out.println(getDaysGap("2023-08-31","2023-05-18"));
//        if ((new BigDecimal("0")).compareTo(new BigDecimal("0.00")) == 0){
//            System.out.println("number is 0");
//        }
//        if (new BigDecimal("0").compareTo(new BigDecimal("0.0")) == 0){
//            System.out.println("number is 0");
//        }
    }
    public static String getDaysGap(String date1, String date2) throws ParseException {
        Integer days = 0;
        // 转成毫秒并求差
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        long m = sdf.parse(date1).getTime() - sdf.parse(date2).getTime();
        days = (int) (m / (1000 * 60 * 60 * 24));
        return days+"";
    }

    public static boolean isValidDateFormat(String dateStr) {
        Pattern pattern = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$");
        Matcher matcher = pattern.matcher(dateStr);
        return matcher.matches();
    }

    public static String getCurrDate(String date) {
        String year = date.substring(0,4);
        String month = date.substring(4,6);
        String day = date.substring(6,8);
        String strDate = year + "-" + month + "-" +day;

        return strDate;
    }

}
